// 检查指定方向棋子是否连续
const checkDirection = (
  row: number,
  col: number,
  dx: number,
  dy: number,
  currentBorder: any[],
  currentPlayer: 1 | 2
): boolean => {
  let count = 1; // 当前位置的棋子算一个
  let x = row + dx;
  let y = col + dy;
  // 向正方向遍历
  while (
    x >= 0 &&
    y >= 0 &&
    x <= currentBorder.length &&
    y <= currentBorder.length &&
    currentBorder[x][y].chess === currentPlayer
  ) {
    count++;
    x += dx;
    y += dy;
  }
  // 反方向遍历
  x = row - dx;
  y = col - dy;
  while (
    x >= 0 &&
    y >= 0 &&
    x <= currentBorder.length &&
    y <= currentBorder.length &&
    currentBorder[x][y].chess === currentPlayer
  ) {
    count++;
    x -= dx;
    y -= dy;
  }
  return count >= 5; // 如果连续的棋子数大于等于5，则返回true
};

export { checkDirection };
